package gupao.concurrency.lock;

import gupao.concurrency.lock.utils.Utils;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

@Slf4j
public class DeadLockMain {
    public static void main(String[] args) throws InterruptedException {
        Thread threadA = new Thread(() -> {
            long start = System.currentTimeMillis();
            while (true) {
                try {
                    SimpleDeadLockSample.workAndSleep();
                } catch (Exception e) {
                }
                Utils.sleepIgnoreExp(200);
                if((System.currentTimeMillis() - start) > 800){
                    break;
                }
            }
        });

        Thread threadB = new Thread(() -> {
            long start = System.currentTimeMillis();
            while (true) {
                try {
                    SimpleDeadLockSample.sleepAndWork();
                } catch (Exception e) {
                }
                Utils.sleepIgnoreExp(200);
                if((System.currentTimeMillis() - start) > 800){
                    break;
                }
            }
        });

        threadA.start();
        threadB.start();
        threadA.join();
        threadB.join();
    }
}
